package linda.test;

import linda.Linda;
import linda.Tuple;

public class BasicTestRMI3 {
	 public static void main(String[] a) {
			
	        final Linda linda = new linda.server.LindaClient("localhost");
	        // final Linda linda = new linda.server.LindaClient("//localhost:4000/aaa");
			
	        new Thread() {
	            public void run() {
	                try {
	                    Thread.sleep(2000);
	                } catch (InterruptedException e) {
	                    e.printStackTrace();
	                }
	                Tuple motif = new Tuple(Integer.class, Integer.class);
	                System.out.println("Test de tryread et trytake");
	                Tuple res = linda.tryRead(motif);
	                System.out.println("(1) Resultat tryread:" + res);
	                linda.debug("(1)");
	                res = linda.tryTake(motif);
	                System.out.println("(1) Resultat trytake:" + res);
	                linda.debug("(1)");
	                
	                // test if the tuple as been removed
	                res = linda.tryRead(motif);
	                Tuple res2 = linda.tryTake(motif);
	                if (res == null & res2 == null)
	                	System.out.println("It works: the matching tuple as been removed by the take method!");
	                else
	                	System.out.println("It doesn't works: the matching tuple asn't been removed by the take method!");
	            }
	        }.start();
			
	        new Thread() {
	            public void run() {
	                try {
	                    Thread.sleep(2);
	                } catch (InterruptedException e) {
	                    e.printStackTrace();
	                }

	                Tuple t1 = new Tuple(4, 5);
	                System.out.println("(2) write: " + t1);
	                linda.write(t1);     
					
	                linda.debug("(2)");

	            }
	        }.start();
			
	    }
}
